package com.ytrsoft.entity;

import com.ytrsoft.enums.Gender;
import com.ytrsoft.enums.RelationshipStatus;
import com.ytrsoft.util.Lang;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;

import java.util.Date;

@Schema(description = "用户类")
@Entity
public class User extends BaseEntity {

    @Schema(description = "设备号")
    @Column(nullable = false, unique = true)
    private String deviceId;

    @Schema(description = "姓名")
    private String name;

    @Schema(description = "出生年月")
    private Date birthday;

    @Schema(description = "性别")
    @Enumerated(EnumType.STRING)
    private Gender gender;

    @Schema(description = "头像")
    private String avatar;

    @Schema(description = "关系状态")
    @Enumerated(EnumType.STRING)
    private RelationshipStatus relationshipStatus;

    @Schema(description = "在线状态")
    private Boolean isOnline = false;

    @Schema(description = "关联角色")
    @ManyToOne
    @JoinColumn(name = "role_id")
    private Role role;

    @Schema(description = "纬度")
    private Double latitude;

    @Schema(description = "经度")
    private Double longitude;

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public RelationshipStatus getRelationshipStatus() {
        return relationshipStatus;
    }

    public void setRelationshipStatus(RelationshipStatus relationshipStatus) {
        this.relationshipStatus = relationshipStatus;
    }

    public Boolean getOnline() {
        return isOnline;
    }

    public void setOnline(Boolean online) {
        isOnline = online;
    }

    public Double getLatitude() {
        return latitude;
    }

    public void setLatitude(Double latitude) {
        this.latitude = latitude;
    }

    public Double getLongitude() {
        return longitude;
    }

    public void setLongitude(Double longitude) {
        this.longitude = longitude;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @Override
    public void prePersist() {
        super.prePersist();
        relationshipStatus = RelationshipStatus.SINGLE;
    }
}
